package com.gem.shop.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author zhang
 * @date 2020/9/16 20:02
 * 订单实体类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "order")
@DynamicUpdate
@DynamicInsert
public class Order {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String orderId;
    private LocalDateTime createTime;

    //多对一
    @ManyToOne
    //外键
    @JoinColumn(name = "customer_id",referencedColumnName = "id")
    private Customer customer;

    //一对多
    @OneToMany(mappedBy = "order",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
    private List<OrderDetails> orderDetails;
}
